<?php
/**
 * Created by PhpStorm.
 * User: J.H
 * Date: 2017/3/16
 * Time: 13:05
 */

namespace lib\aliYun\sms;

use lib\aliYun\ApiBase;

class ApiSms extends ApiBase
{

    function __construct()
    {
        parent::__construct();
        $this->AccessKeyId = 'LTAIDEj0Fv32N2DR';
        $this->AccessKeySecret = 'QMHak0P4sBPQIdftjuIdHNBstQrrcC';
        $this->Version = '2016-09-27';
        $this->SignatureVersion = '1.0';

    }

    /**
     * 发送短信
     *
     * @param string|array $to
     * @param string $templateCode
     * @param array $params
     * @param string $signName
     *
     * @return $this
     */
    function singleSendSms($to, $templateCode, array $params, $signName = '签名')
    {
        $this->setParam('Action', 'SingleSendSms');
        $this->setParam('SignName', $signName);
        $this->setParam('TemplateCode', $templateCode);
        $this->setParam('ParamString', json_encode($params, 256));
        if (is_array($to)) {
            $to = implode(',', $to);
        }
        $this->setParam('RecNum', $to);
        $this->buildParams();
        return $this;
    }

}